package com.backgroundManager.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.backgroundManager.biz.UserMgr.IUserMgr;
import com.opensymphony.xwork2.ActionSupport;
import com.usermgr.bean.OfUser;

/**
 *@title      	标题：
 *@description 	描述：
 *@author 	  	作者 ：wuxionghao
 *@createTime 	创建时间：2012-1-9下午03:24:45
 *@version    	版本：v1.0
 */
public class UserMgrAction extends ActionSupport {
	
	private IUserMgr userMgr;
	
	private OfUser user;
	
	private String resultStatus ;
	/**
	 * 进入后台管理页面
	 */
	@Override
	public String execute() throws Exception {
		String result = "";
		Long userId = (Long)ServletActionContext.getRequest().getSession().getAttribute("userId");	//取得用户名
		if(userId != null && userMgr.judgeUserPermission(userId)){
			List<OfUser> list = userMgr.selectUser();
			ServletActionContext.getRequest().setAttribute("allUser", list);
			result = "success";
		}else{
			result = "faild";
			ServletActionContext.getRequest().setAttribute("check", "您不是管理员，您 不能进入后台");
		}
		return result;
	}
	/**
	 * 更改用户权限
	 * @return
	 */
	public String updatepermission(){
		String result = "fail";
		Long userId = user.getOfId();
		String permission = user.getOfPermission();
		List<OfUser> list = userMgr.selectUser();
		ServletActionContext.getRequest().setAttribute("allUser", list);
		if(userMgr.updateUserPermission(userId, permission)){
			result = "success";
			resultStatus = "更改成功";
		}else{
			resultStatus = "更改失败";
		}
		return result;
	}
	public IUserMgr getUserMgr() {
		return userMgr;
	}
	public void setUserMgr(IUserMgr userMgr) {
		this.userMgr = userMgr;
	}
	public OfUser getUser() {
		return user;
	}
	public void setUser(OfUser user) {
		this.user = user;
	}
	public String getResultStatus() {
		return resultStatus;
	}
	public void setResultStatus(String resultStatus) {
		this.resultStatus = resultStatus;
	}
}
